package com.eclipse.training.extensions.views;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.forms.widgets.TableWrapData;
import org.eclipse.ui.forms.widgets.TableWrapLayout;
import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;

/**
 * The abstract class implementing a property section showed in the tabbed
 * property view.
 */
public abstract class AbstractTrainingPropertySection extends
		AbstractPropertySection {
	protected Composite client;
	protected String title;
	protected String description;

	@Override
	public void createControls(Composite parent,
			TabbedPropertySheetPage aTabbedPropertySheetPage) {
		super.createControls(parent, aTabbedPropertySheetPage);

		Composite composite = getWidgetFactory()
				.createFlatFormComposite(parent);

		FormData data = new FormData();
		data.left = new FormAttachment(0, 5);
		data.right = new FormAttachment(100, 0);

		Section section = getWidgetFactory()
				.createSection(
						composite,
						(description != null && description.length() > 0 ? Section.DESCRIPTION
								: 0)
								| Section.TITLE_BAR);

		section.setText(title);
		if (description != null && description.length() > 0)
			section.setDescription(description);

		section.setLayout(new TableWrapLayout());
		section.setLayoutData(data);

		client = getWidgetFactory().createComposite(section, SWT.NONE);

		TableWrapLayout layout = new TableWrapLayout();
		layout.numColumns = 2;
		client.setLayout(layout);
		client.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB,
				TableWrapData.FILL_GRAB));

		section.setClient(client);

	}
}
